/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package org.sack.picasawebalbums;

import com.google.gdata.client.photos.PicasawebService;
import com.google.gdata.data.photos.AlbumFeed;
import com.google.gdata.data.photos.UserFeed;
import com.google.gdata.util.AuthenticationException;
import com.google.gdata.client.GoogleService.InvalidCredentialsException;
import com.google.gdata.util.ServiceException;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import org.openide.util.Exceptions;

/**
 *
 * @author admin
 */
public class Feeds {
    PicasawebService myService;
    private String Username, Password;
    private UserFeed userfeed;
    private AlbumFeed albumfeed;
    public Feeds(String Username, String Password)throws AuthenticationException,InvalidCredentialsException{
        //creating Picasa Service
        myService = new PicasawebService("NB Service");
        this.Username=Username;
        this.Password = Password;
        myService.setUserCredentials(Username+"@gmail.com", Password);
    }
    public UserFeed getUserFeed(){
        try {
            URL userUrl = new URL("http://picasaweb.google.com/data/feed/api/user/"+Username+"?kind=album");
            userfeed = myService.getFeed(userUrl, UserFeed.class);
        }  catch (ServiceException ex) {
            Exceptions.printStackTrace(ex);
        }  catch (MalformedURLException ex) {
            Exceptions.printStackTrace(ex);
        }  catch (IOException ex) {
            Exceptions.printStackTrace(ex);
        }
        return userfeed;
    }
    public AlbumFeed getAlbumFeed(String AlbumName)throws java.net.SocketException{
        try {
            //getting AlbumInfo and declaring album size
            URL albumUrl = new URL("http://picasaweb.google.com/data/feed/api/user/" + Username + "/album/" + AlbumName + "?kind=photo&imgmax=576");
            albumfeed = myService.getFeed(albumUrl, AlbumFeed.class);
            }catch (MalformedURLException ex) {
            Exceptions.printStackTrace(ex);
            }catch (IOException ex) {
            Exceptions.printStackTrace(ex);
            }catch (ServiceException ex) {
            Exceptions.printStackTrace(ex);
            }
        
         
        return albumfeed;
    }
    public PicasawebService getPicasawebService(){
        return myService;
    }
}